<template>
    <div class="app-container">
    
        <div class="filter-container add1">
    
            <el-form style="">
    
                <el-form-item>
    
                    <!-- 按钮级别的控制,使用hasPerm来判断是否应该有添加这个按钮 -->
    
                    <el-button type="primary" icon="plus" size="medium" @click="showCreate" v-if="hasPerm('article:add')">添加
    
                    </el-button>
    
                    <!-- 下载模板 -->
                    <a href="/src/views/article/2019416.xlsx">
                        <el-button type="success" size="medium" icon="plus" v-if="hasPerm('article:add')">下载导入模板
                        </el-button>
                    </a>
                     <!-- 后端导入 -->
                    <el-upload
                        :show-file-list="false"
                        accept="application/vnd.ms-excel"
                        :action="uploadUrl()"
                        :on-success="fileUploadSuccess"
                        :on-error="fileUploadError" 
                        :disabled="fileUploadBtnText=='正在导入'"
                        :before-upload="beforeFileUpload" style="display: inline">
                        <el-button size="medium" type="success" :loading="fileUploadBtnText=='正在导入'"><i class="fa fa-lg fa-level-up" style="margin-right: 5px"></i>{{fileUploadBtnText}}
                        </el-button>
                    </el-upload>

                    <el-button @click="exportExcelOpertor" type="primary" size="medium" icon="plus" v-if="hasPerm('article:add')">前台导出</el-button>
                    <!-- <el-button @click="exportExcelByback" type="primary" size="medium" icon="plus" v-if="hasPerm('article:add')">后台导出</el-button> -->
                    <el-button @click="showDisplay" type="info" size="medium" icon="plus">显示字段</el-button>
                    <!-- <el-button @click="exportExcel" type="primary" icon="plus" v-if="hasPerm('article:add')" >导出</el-button> -->
                    <el-button type="danger" size="medium" v-if="multipleSelectionFlag" @click="delSelect">
    
                        批量删除
    
                    </el-button>
    
                    <el-button type="primary" size="medium" icon="plus" @click="showUserInfo" v-if="hasPerm('article:add')">获得该用户信息
    
                    </el-button>

                     <!-- 后端导入 -->
                    <el-upload
                        :show-file-list="false"
                        accept="application/vnd.ms-excel"
                        :action="uploadUrlDingdan()"
                        :on-success="fileUploadSuccess"
                        :on-error="fileUploadError" 
                        :disabled="fileUploadBtnText=='正在导入'"
                        :before-upload="beforeFileUpload" style="display: inline">
                        <el-button size="medium" type="success" :loading="fileUploadBtnText=='正在导入'"><i class="fa fa-lg fa-level-up" style="margin-right: 5px"></i>{{fileUploadBtnText}}
                        </el-button>
                    </el-upload>
    
                </el-form-item>
    
            </el-form>
    
    
    
        </div>
    
        <div class="searchWord">
    
            <!-- style="display: inline-block;"  -->
    
            <el-input v-model="search" placeholder="请输入搜索内容" @input="inputFunction()">
    
            </el-input>
    
        </div>
    
        <br>
    
        <el-table class="tabless" :data="list" v-loading.body="listLoading" element-loading-text="拼命加载中" border fit highlight-current-row :row-class-name="tableRowClassName" @sort-change='sortChange' @selection-change="handleSelectionChange">
    
            <el-table-column type="selection" width="55" v-if="displayAttribute.select">
    
            </el-table-column>
    
            <el-table-column align="center" label="序号" width="80" v-if="displayAttribute.id">
    
                <template slot-scope="scope">
    
              <!-- 文章的索引 -->
    
              <span v-text="getIndex(scope.$index)"> </span>
    
              <!-- 文章的id -->
    
              <!-- <span v-text="scope.row.id"> </span> -->
</template>
      </el-table-column>
      <el-table-column align="center" prop="content" label="内容" style="width: 60px;" sortable='custom' v-if="displayAttribute.content"></el-table-column>
      <el-table-column align="center" label="创建时间" width="170" sortable='customsss' prop = "createTime" v-if="displayAttribute.createTime">
        <!--<template slot-scope="scope">
    <span>{{scope.row.createTime}}</span>
</template>-->
      </el-table-column>

      <el-table-column align="center" label="管理" width="300" v-if="hasPerm('article:update') & displayAttribute.manageMent">
<template slot-scope="scope">
    <el-button type="primary" icon="edit" @click="showDetails(scope.$index)">
    
        详情</el-button>
    
    <el-button type="primary" icon="edit" @click="showUpdate(scope.$index)">修改</el-button>
    
    <el-button type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
</template>
      </el-table-column>
    </el-table>

    <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow" >确 定</el-button>
            </span>
        </el-dialog>

        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisibleByBatch" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定批量删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisibleByBatch = false">取 消</el-button>
                <el-button type="primary" @click="delAll" >确 定</el-button>
            </span>
        </el-dialog>
    
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listQuery.pageNum" 
      :page-size="listQuery.pageRow"
      :total="totalCount"
      :page-sizes="[3, 20, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper"
      class="pagination">
    </el-pagination>

    
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
      <el-form class="small-space" :model="tempArticle" label-position="left" label-width="60px"
               style='width: 300px; margin-left:50px;'>
        <el-form-item label="文章" v-if="dialogStatus=='create' | dialogStatus=='update'">
          <input type="text" v-model="tempArticle.content" @keyup = "handlerArticle">
          </input>
          <el-tag type="danger" v-if="this.displayInfoFromBack">{{infoFromBack}}</el-tag>
          
        </el-form-item>
        <!-- v-if="dialogStatus=='details'" -->
        <el-row class="demo-autocomplete" v-if="dialogStatus=='details'">
          <el-col :span="12">
            <el-autocomplete
              class="inline-input"
              v-model="state1"
              :fetch-suggestions="querySearch"
              placeholder="请输入内容"
              @select="handleSelect"
            ></el-autocomplete>
          </el-col>
          <!-- <el-col :span="12">
            <div class="sub-title">输入后匹配输入建议</div>
            <el-autocomplete
              class="inline-input"
              v-model="state2"
              :fetch-suggestions="querySearch"
              placeholder="请输入内容"
              :trigger-on-focus="false"
              @select="handleSelect"
            ></el-autocomplete>
          </el-col> -->
        </el-row>


        <div v-if="dialogStatus=='dispalyAtt'">
          <el-checkbox v-model="displayAttribute.select">复选框</el-checkbox><br>
          <el-checkbox v-model="displayAttribute.id">序号</el-checkbox><br>
          <el-checkbox v-model="displayAttribute.content">内容</el-checkbox><br>
          <el-checkbox v-model="displayAttribute.createTime">创建时间</el-checkbox> <br>
          <el-checkbox v-model="displayAttribute.manageMent">管理</el-checkbox>

        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button v-if="dialogStatus=='create'" type="success" @click="createArticle" :disabled = "enableCreate">创 建</el-button>
        <el-button type="primary" v-if="dialogStatus=='update'" @click="updateArticle" >修 改</el-button>
        
      </div>
    </el-dialog>
  </div>
</template>
<script>
import FileSaver from "file-saver";
import XLSX from "xlsx";
import { mapGetters } from 'vuex';

import $ from 'jquery'
// import "../../../node_modules/jquery-table2excel/dist/jquery.table2excel.min"

export default {
    data() {
        return {
            fileUploadBtnText : "后端导入",
            // 实时搜索
            restaurants: [
                // { "value": "天天推" },
                // { "value": "愿意要" },
                // { "value": "大撒打"},
                // { "value": "大撒大撒的", "address": "天山西路438号" },
            ],
            state1: '',
            state2: '',
            // 实时搜索结束 

            totalCount: 0, //分页组件--数据总条数
            list: [], //表格的数据
            listLoading: false, //数据加载等待动画
            listQuery: {
                pageNum: 1, //页码
                pageRow: 3, //每页条数
                name: ''
            },
            // 为textMap中的属性,指定标题头
            dialogStatus: 'create',
            dialogFormVisible: false,
            textMap: {
                update: '编辑',
                create: '创建文章',
                dispalyAtt: '显示字段',
                details: '详情',
            },
            tempArticle: {
                id: "",
                content: ""
            },
            tempObj: {
                id: '',
                value: ''
            },
            delVisible: false, //删除提示弹框的状态
            delVisibleByBatch: false, //批量删除提示弹框的状态
            msg: "", //记录每一条的信息，便于取id
            delarr: [], //存放删除的数据
            multipleSelection: [], //多选的数据
            // 搜索框中的内容
            search: '',
            // 排序的列名
            prop: '',
            // 排序的方式:包括asc,desc等
            order: '',
            // 记录导出得时候跳页的之前的页数
            temp_page: 3,

            // 从后台返回来的数据
            infoFromBack: '',

            displayInfoFromBack: false,

            enableCreate: false,

            multipleSelectionFlag: true,
            // 记录显示字段
            displayAttribute: {
                select: true,
                id: true,
                content: true,
                createTime: true,
                manageMent: true
            }
        }
    },
    computed: {
        ...mapGetters([
            'userId',
            'nickname'
        ])
    },
    created() {
        // alert("1");
        this.getList();
        // alert("xxxxxx");
    },

    mounted() {
        // alert("2");
        // this.getListTest();

        // console.log('restaurants1:', this.restaurants);
        // this.restaurants = this.loadAll();
        // console.log('list:', this.list)
        // for(var i = 0 ; i < this.list.length ; i++){
        //   var temp = this.list[i];
        //   console.log('temp:', temp)
        //   this.restaurants.push(temp);
        //   console.log('restaurants:', this.restaurants)
        // }
        // // this.restaurants = this.list;
        // console.log('restaurants2:', this.restaurants);
        this.getListTest();
    },
    methods: {
        uploadUrl:function(){
            return "/api/excel/importArticle";
        },
        uploadUrlDingdan:function(){
            return "/api/excel/importDingdan";
        },
        
        handlerArticle() {
            console.log("content:", this.tempArticle.content);
            // return;
            this.api({
                url: "/article/getArticleByContent",
                method: "get",
                params: this.tempArticle
            }).then(data => {
                console.log("data:", data);
                if (data === "fail") {
                    // alert("无效");
                    this.displayInfoFromBack = true;
                    this.infoFromBack = "无效";
                    this.enableCreate = true;
                } else {
                    this.displayInfoFromBack = false;
                    this.infoFromBack = "";
                    this.enableCreate = false;
                }

            })
        },
        // 获得用户信息
        showUserInfo() {
            console.log('userId:', this.userId);
            console.log('nickname', this.nickname);
        },



        clearFile() {
            this.$refs.clearFile.value = ''; // 清空file文件
        },
        // 导入
        importf(obj) {
            let _this = this;
            let inputDOM = this.$refs.inputer; // 通过DOM取文件数据
            this.file = event.currentTarget.files[0];
            var rABS = false; //是否将文件读取为二进制字符串
            var f = this.file;
            var reader = new FileReader();
            //if (!FileReader.prototype.readAsBinaryString) {
            FileReader.prototype.readAsBinaryString = function(f) {
                var binary = "";
                var rABS = false; //是否将文件读取为二进制字符串
                var pt = this;
                var wb; //读取完成的数据
                var outdata;
                var reader = new FileReader();
                reader.onload = function(e) {
                    var bytes = new Uint8Array(reader.result);
                    var length = bytes.byteLength;
                    for (var i = 0; i < length; i++) {
                        binary += String.fromCharCode(bytes[i]);
                    }
                    var XLSX = require('xlsx');
                    if (rABS) {
                        wb = XLSX.read(btoa(fixdata(binary)), { //手动转化
                            type: 'base64'
                        });
                    } else {
                        wb = XLSX.read(binary, {
                            type: 'binary'
                        });
                    }
                    // outdata就是你想要的东西 excel导入的数据
                    outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
                    // excel 数据再处理
                    let arr = []
                    outdata.map(v => {
                        // console.log(v)
                        let obj = {}
                        obj.content = v.内容
                        obj.id = ""
                        arr.push(obj)
                        _this.tempArticle = obj
                        console.log(_this.tempArticle)
                        _this.createArticle()
                        // this.api({
                        //   url: "/article/addArticle",
                        //   method: "post",
                        //   data: obj
                        // }).then(() => {
                        //   this.getList();
                        //   // this.dialogFormVisible = false
                        // })
                    })
                    _this.accountList = [...arr];
                    console.log(_this.accountList)
                    // _this.reload();
                    // console.log('uuuuuuuuuuuuuuuuuuuuu');
                }
                alert("上传完毕！")
                _this.clearFile()
                reader.readAsArrayBuffer(f);
            }
            if (rABS) {
                reader.readAsArrayBuffer(f);
            } else {
                reader.readAsBinaryString(f);
            }
        },
        // exportArticle() {
        //     this.api({
        //         url: "/excel/getArticleExcel",
        //         method: "get",
        //     }).then(data => {
        //         console.log('getArticleExcel:', data)
        //     })
        // },
        // 导入结束

        exportExcelByback() {
            this.api({
                    url: "/excel/exportArticle",
                    method: "get",
                    
                }).then(() => {
                    // console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
                    alert("导出成功");
                    console.log("导出成功");
                }).catch((err) => {
                    console.log('err:', err);
                    this.$message.error("删除失败")
                })
            // window.location.href= "/excel/exportArticle";

        },

        exportExcelOpertor() {
            this.temp_page = this.listQuery.pageRow;
            // this.displayAttribute.select = false;
            // this.displayAttribute.manageMent = false;
            console.log(this.totalCount);
            this.handleSizeChange(this.totalCount)
            window.setTimeout(this.exportExcel, 1000);
            window.setTimeout(this.delayTime, 1120);


        },
        
        delayTime() {
            this.listQuery.pageRow = this.temp_page
            // this.displayAttribute.select = true;
            // this.displayAttribute.manageMent = true;
            this.generalFun();
        },
        exportExcel() {
            // alert("exportExcel")
            // 设置当前日期
            let time = new Date();
            let year = time.getFullYear();
            let month = time.getMonth() + 1;
            let day = time.getDate();
            let name = year + "" + month + "" + day;
            this.$nextTick(function() {
                // alert("iiiiiiiiiiiiiiiii");
                // alert(tempPageSize);
                let wb = XLSX.utils.table_to_book(document.querySelector('.tabless'));

                /* get binary string as output */
                let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
                try {
                    FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), name + ".xlsx")
                } catch (e) {
                    if (typeof console !== 'undefined') console.log(e, wbout)
                }
                // this.listQuery.pageRow = 3;//表格还原
                // this.getList();
                return wbout
            })
            // $(".tabless").table2excel({
            //   //需要导出的列
            //   columns:"1,2,3",
            //   // 不被导出的表格行的CSS class类
            //   exclude: ".noExl",
            //   // 导出的Excel文档的名称
            //   name: "Excel",
            //   // Excel文件的名称
            //   filename: "Excel",
            //   // 是否导出图片
            //   exclude_img: true,
            //   // 是否导出超链接
            //   exclude_links: true,
            //   // 是否导出输入框中的内容
            //   exclude_inputs: true
            // });

        },


        inputFunction() {
            // console.log('zandaoguang');
            console.log(this.search);
            console.log(this.search == "");

            if (this.search) {
                // console.log('aaaaaaaaaaaaaaaa');
                this.getListBySearch(this.search);
            }
            if (this.search == "") {
                this.getList();
            }
        },
        sortChange(column, prop, order) {

            // this.handleCurrentChange(1);
            this.listQuery.pageNum = 1;         // 点击排序按钮后拿到column.order，可以发送column.order给后台，后台再根据什么排序来返回排序过后的数据
            // console.log(column);
                     // console.log(column + '---' + column.prop + '---' + column.order)
            // this.prop = column.prop;
            // this.order = column.order;
            // console.log(this.prop);
            // console.log(column.prop);
            // console.log(this.order);
            // 如果搜索框中没有搜索内容
            if (this.search == "") {
                if (column.order === "descending") {
                    this.listQuery.sortby = column.prop;
                    this.listQuery.order = 'DESC';
                    // this.prop = column.prop;
                    // this.order = 'DESC';
                } else {
                    this.listQuery.sortby = column.prop;
                    this.listQuery.order = 'ASC';
                    // this.prop = column.prop;
                    // this.order = 'ASC';
                }
                if (column.prop == "content") {
                    this.getListByOrderContent();
                    // this.prop = '';
                    // this.order = '';
                } else if (column.prop == "createTime") {
                    this.getListByOrderCreateTime();
                    // this.prop = '';
                    // this.order = '';
                } else {
                    // 默认返回id排序
                    this.getList();
                }
            }
            // 如果搜索框中有搜索内容
            else {
                if (column.order === "descending") {
                    this.listQuery.sortby = column.prop;
                    this.listQuery.order = 'DESC';
                    // this.prop = column.prop;
                    // this.order = 'DESC';
                } else {
                    this.listQuery.sortby = column.prop;
                    this.listQuery.order = 'ASC';
                    // this.prop = column.prop;
                    // this.order = 'ASC';
                }
                if (column.prop == "content") {
                    this.getListByContentHaveSearch();
                    // this.prop = '';
                    // this.order = '';
                } else if (column.prop == "createTime") {
                    // 当空格的时候，应该怎么排序
                    // this.getListByOrderCreateTime();
                    // 默认按照id排序
                    // this.getListBySearch(this.search);
                    this.getListByOrderCreateTimeHaveSearch();
                    // this.prop = '';
                    // this.order = '';
                } else {
                    // 默认什么都不做
                    // 默认返回id排序
                    this.getListBySearch(this.search);
                }
            }       //输出的结果 [object Object]---name---ascending
                  
        },
        //单行删除
        handleDelete(index, row) {
            console.log("index:" + index);
            console.log(row);
            this.idx = index;
            this.msg = row; //每一条数据的记录
            console.log("this.msg.PackingId : " + this.msg.PackingId);
            this.delarr.push(this.msg.PackingId); //把单行删除的每条数据的id添加进放删除数据的数组
            console.log("this.delarr : " + this.delarr);
            this.delVisible = true;
        },
        // 当批量删除的时候,如果要是没有选中,弹出提醒
        delWarnInfo() {
            this.$message('请选择您要删除的数据');
        },
        //批量删除
        delAll() {
            // alert("我进来啦~");
            var lengths = this.multipleSelection.length;

            for (let i = 0; i < lengths; i++) {
                // console.log('aaaaaaaaaaaaaaaaaaaaaaaa');
                console.log(this.multipleSelection[i]);
                this.multipleSelection[i].deleteStatus = '2';
                this.api({
                    url: "/article/deleteArticle",
                    method: "post",
                    data: this.multipleSelection[i]
                }).then(() => {
                    // console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
                    if (this.search == "") {
                        // alert("我不空啊")
                        this.getList();
                    } else {
                        // alert("我怎么就空了呢？")
                        this.getListBySearch(this.search);
                    }
                }).catch(() => {
                    this.$message.error("删除失败")
                })

            }
            this.delVisibleByBatch = false; //关闭删除提示模态框
        },

        // 确定删除
        deleteRow() {
            let _vue = this;
            // 写自己的删除的对象
            // console.log(this.delarr)
            console.log("_vue.list" + _vue.list);
            console.log("_vue.index:" + _vue.idx);
            let article = _vue.list[_vue.idx];
            article.deleteStatus = '2';
            console.log("article:");
            console.log(article);
            _vue.api({
                url: "/article/deleteArticle",
                method: "post",
                data: article
            }).then(() => {
                console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
                if (this.search == "") {
                    _vue.getList();
                } else {
                    // alert("我怎么就空了呢？")
                    _vue.getListBySearch(this.search);
                }
            }).catch(() => {
                _vue.$message.error("删除失败")
            })
            // user.deleteStatus = '2';
            // _vue.api({
            //   url: "/user/updateUser",
            //   method: "post",
            //   data: user
            // }).then(() => {
            //   _vue.getList()
            // }).catch(() => {
            //   _vue.$message.error("删除失败")
            // })
            this.delVisible = false; //关闭删除提示模态框
        },
        toggleSelection(rows) {
            if (rows) {
                rows.forEach(row => {
                    this.$refs.multipleTable.toggleRowSelection(row);
                });
            } else {
                this.$refs.multipleTable.clearSelection();
            }
        },
        delSelect() {
            const length = this.multipleSelection.length;
            if (length == 0) {
                this.delWarnInfo();
            } else {
                this.delVisibleByBatch = true; //显示删除弹框
            }
            // this.delAll();
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            console.log(this.multipleSelection);
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 === 1) {
                return 'warning-row';
            } else if (rowIndex % 2 === 0) {
                // return 'success-row';
            }
            return '';
        },
        getListTest() {
            //查询列表
            if (!this.hasPerm('article:list')) {
                return
            }
            this.listLoading = true;
            this.api({
                url: "/article/listArticle",
                method: "get",
                params: this.listQuery
            }).then(data => {
                // console.log('我真的帅啊！');
                // console.log("data:",data)
                // return;
                console.log('list:', data.list)
                // 先将json对象转为json字符串，再替换你要替换的属性名，最后再转为json对象
                // console.log('string:', JSON.stringify())
                var json = JSON.parse(JSON.stringify(data.list).replace(/content/g, "value"));
                // console.log("json:",json)
                // for(var i = 0 ; i < data.list.length ; i++){
                // var temp1;
                // console.log('listi:', data.list[i]);
                // console.log('value', data.list[i].content)
                // temp1.value = '';
                // temp1.id = '';
                // console.log('valuessss', this.tempObj.value)
                // console.log('idsssss', this.tempObj.id)
                // this.tempObj.value = data.list[i].content;
                // // console.log('id', data.list[i].id)
                // this.tempObj.id = data.list[i].id;
                //  console.log('valuessss', this.tempObj.value)
                // console.log('idsssss', this.tempObj.id)
                // console.log('tempOb:', this.tempObj);
                // this.restaurants.push(this.tempObj);
                // console.log('restaurants:', this.restaurants)
                // }
                this.restaurants = json;
                // console.log("restaurants:",this.restaurants);
            })
        },
        getList() {
            //查询列表
            if (!this.hasPerm('article:list')) {
                return
            }
            this.listLoading = true;
            this.api({
                url: "/article/listArticle",
                method: "get",
                params: this.listQuery
            }).then(data => {
                // console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
                console.log(data)
                this.listLoading = false;
                this.list = data.list;
                this.tables = data.list;
                this.totalCount = data.totalCount;
            })
        },
        getListByOrderContent() {
            //查询列表

            if (!this.hasPerm('article:list')) {
                return
            }
            this.listLoading = true;
            this.api({
                url: "/article/listArticleByOrder",
                method: "get",
                params: this.listQuery
            }).then(data => {
                // console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
                // console.log(data)
                this.listLoading = false;
                this.list = data.list;
                this.tables = data.list;
                this.totalCount = data.totalCount;
            })
        },

        // 当搜索框中有内容的时候，排序的时候需要只排序搜索出来的内容
        getListByContentHaveSearch() {
            //查询列表

            if (!this.hasPerm('article:list')) {
                return
            }
            this.listLoading = true;
            this.listQuery.value = this.search;
            this.api({
                url: "/article/listArticleByContentHaveSearch",
                method: "get",
                params: this.listQuery
            }).then(data => {
                console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
                console.log(data)
                this.listLoading = false;
                this.list = data.list;
                this.tables = data.list;
                this.totalCount = data.totalCount;
            })
        },

        getListByOrderCreateTimeHaveSearch() {
            //查询列表

            if (!this.hasPerm('article:list')) {
                return
            }
            this.listLoading = true;
            this.listQuery.value = this.search;
            this.api({
                url: "/article/getListByOrderCreateTimeHaveSearch",
                method: "get",
                params: this.listQuery
            }).then(data => {
                console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
                console.log(data)
                this.listLoading = false;
                this.list = data.list;
                this.tables = data.list;
                this.totalCount = data.totalCount;
            })
        },
        getListByOrderCreateTime() {
            //查询列表

            if (!this.hasPerm('article:list')) {
                return
            }
            this.listLoading = true;
            this.api({
                url: "/article/listArticleByOrderCreateTime",
                method: "get",
                params: this.listQuery
            }).then(data => {
                console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
                console.log(data)
                this.listLoading = false;
                this.list = data.list;
                this.tables = data.list;
                this.totalCount = data.totalCount;
            })
        },

        getListBySearch(val) {
            // console.log("val:"+val);
            //查询列表
            if (!this.hasPerm('article:list')) {
                return
            }
            this.listLoading = true;
            this.listQuery.value = val;
            // console.log(this.listQuery);
            this.api({
                url: "/article/listArticleBySearch",
                method: "get",
                params: this.listQuery
            }).then(data => {
                // console.log(data)
                this.listLoading = false;
                this.list = data.list;
                this.totalCount = data.totalCount;
            })
        },
        handleSizeChange(val) {
            //改变每页数量
            // alert("handleSizeChange()")
            this.listQuery.pageRow = val
            this.generalFun();
            // this.handleFilter();
        },
        handleCurrentChange(val) {
            //改变页码


            console.log("sortby:", this.listQuery.sortby)
            console.log("order:", this.listQuery.order)
            this.listQuery.pageNum = val
            this.generalFun();

        },
        getIndex($index) {
            //表格序号
            return (this.listQuery.pageNum - 1) * this.listQuery.pageRow + $index + 1
        },
        showCreate() {
            //显示新增对话框
            this.tempArticle.content = "";
            this.dialogStatus = "create"
            this.dialogFormVisible = true
        },
        showDisplay() {
            this.dialogStatus = "dispalyAtt"
            this.dialogFormVisible = true
        },
        showDetails() {
            this.dialogStatus = "details"
            this.dialogFormVisible = true
        },
        showUpdate($index) {
            //显示修改对话框
            //绑定相应的id
            this.tempArticle.id = this.list[$index].id;
            //绑定相应的内容
            this.tempArticle.content = this.list[$index].content;
            this.dialogStatus = "update"
            this.dialogFormVisible = true
        },
        createArticle() {
            //保存新文章
            // console.log(this.tempArticle)
            // return;
            this.api({
                url: "/article/addArticle",
                method: "post",
                data: this.tempArticle
            }).then(() => {
                this.getList();
                this.dialogFormVisible = false
            })
        },
        updateArticle() {
            console.log("tempArticle:" + this.tempArticle);
            //修改文章
            this.api({
                url: "/article/updateArticle",
                method: "post",
                data: this.tempArticle
            }).then(() => {
                this.getList();
                this.dialogFormVisible = false
            })
        },

        generalFun() {
            this.getListTest();
            if (this.search) {
                if (this.listQuery.sortby == "" & this.listQuery.order == "") {

                    this.getListBySearch(this.search);
                } else if (this.listQuery.sortby == "content" && this.listQuery.order == "ASC") {
                    // alert("你好啊")
                    // this.listQuery.sortby = this.prop;
                    // this.listQuery.order = "ASC";
                    this.getListByContentHaveSearch();
                } else if (this.listQuery.sortby == "content" && this.listQuery.order == "DESC") {
                    // alert("很好啊")
                    // this.listQuery.sortby = this.prop;
                    // this.listQuery.order = "DESC";
                    this.getListByContentHaveSearch();
                } else if (this.listQuery.sortby == "createTime" && this.listQuery.order == "ASC") {
                    // this.listQuery.sortby = this.prop;
                    // this.listQuery.order = "ASC";
                    this.getListByOrderCreateTimeHaveSearch();
                } else if (this.listQuery.sortby == "createTime" && this.listQuery.order == "DESC") {
                    // this.listQuery.sortby = this.prop;
                    // this.listQuery.order = "DESC";
                    this.getListByOrderCreateTimeHaveSearch();
                } else {
                    // alert("xxxxxx");
                    this.getListBySearch(this.search);
                    // ...
                }
            }
            // 没有搜索内容，所以可以直接
            else {
                // alert("ssssssssssssssssss")
                // console.log(this.prop);
                // console.log(this.order);
                if (this.listQuery.sortby == "" & this.listQuery.order == "") {

                    this.getList();
                } else if (this.listQuery.sortby == "content" && this.listQuery.order == "ASC") {
                    // this.listQuery.sortby = this.prop;
                    // this.listQuery.order = "ASC";
                    // ...
                    this.getListByOrderContent();
                } else if (this.listQuery.sortby == "content" && this.listQuery.order == "DESC") {
                    // this.listQuery.sortby = this.prop;
                    // this.listQuery.order = "DESC";
                    this.getListByOrderContent();
                } else if (this.listQuery.sortby == "createTime" && this.listQuery.order == "ASC") {
                    // this.listQuery.sortby = this.prop;
                    // this.listQuery.order = "ASC";
                    this.getListByOrderCreateTime();
                } else if (this.listQuery.sortby == "createTime" && this.listQuery.order == "DESC") {
                    // this.listQuery.sortby = this.prop;
                    // this.listQuery.order = "DESC";
                    this.getListByOrderCreateTime();
                } else {
                    // ...
                    this.getList();
                    // alert("我是空的！")
                }
            }
        },
        loadAll() {
            return [
                { "value": "三全鲜食（北新泾店）", "address": "长宁区新渔路144号" },
                { "value": "Hot honey 首尔炸鸡（仙霞路）", "address": "上海市长宁区淞虹路661号" },
                { "value": "新旺角茶餐厅", "address": "上海市普陀区真北路988号创邑金沙谷6号楼113" },
                { "value": "泷千家(天山西路店)", "address": "天山西路438号" },
                { "value": "胖仙女纸杯蛋糕（上海凌空店）", "address": "上海市长宁区金钟路968号1幢18号楼一层商铺18-101" },
                { "value": "贡茶", "address": "上海市长宁区金钟路633号" },
                { "value": "豪大大香鸡排超级奶爸", "address": "上海市嘉定区曹安公路曹安路1685号" },
                { "value": "茶芝兰（奶茶，手抓饼）", "address": "上海市普陀区同普路1435号" },
                { "value": "十二泷町", "address": "上海市北翟路1444弄81号B幢-107" },
                { "value": "星移浓缩咖啡", "address": "上海市嘉定区新郁路817号" },
                { "value": "阿姨奶茶/豪大大", "address": "嘉定区曹安路1611号" },
                { "value": "新麦甜四季甜品炸鸡", "address": "嘉定区曹安公路2383弄55号" },
                { "value": "Monica摩托主题咖啡店", "address": "嘉定区江桥镇曹安公路2409号1F，2383弄62号1F" },
                { "value": "浮生若茶（凌空soho店）", "address": "上海长宁区金钟路968号9号楼地下一层" },
                { "value": "NONO JUICE  鲜榨果汁", "address": "上海市长宁区天山西路119号" },
                { "value": "CoCo都可(北新泾店）", "address": "上海市长宁区仙霞西路" },
                { "value": "快乐柠檬（神州智慧店）", "address": "上海市长宁区天山西路567号1层R117号店铺" },
                { "value": "Merci Paul cafe", "address": "上海市普陀区光复西路丹巴路28弄6号楼819" },
                { "value": "猫山王（西郊百联店）", "address": "上海市长宁区仙霞西路88号第一层G05-F01-1-306" },
                { "value": "枪会山", "address": "上海市普陀区棕榈路" },
                { "value": "纵食", "address": "元丰天山花园(东门) 双流路267号" },
                { "value": "钱记", "address": "上海市长宁区天山西路" },
                { "value": "壹杯加", "address": "上海市长宁区通协路" },
                { "value": "唦哇嘀咖", "address": "上海市长宁区新泾镇金钟路999号2幢（B幢）第01层第1-02A单元" },
                { "value": "爱茜茜里(西郊百联)", "address": "长宁区仙霞西路88号1305室" },
                { "value": "爱茜茜里(近铁广场)", "address": "上海市普陀区真北路818号近铁城市广场北区地下二楼N-B2-O2-C商铺" },
                { "value": "鲜果榨汁（金沙江路和美广店）", "address": "普陀区金沙江路2239号金沙和美广场B1-10-6" },
                { "value": "开心丽果（缤谷店）", "address": "上海市长宁区威宁路天山路341号" },
                { "value": "超级鸡车（丰庄路店）", "address": "上海市嘉定区丰庄路240号" },
                { "value": "妙生活果园（北新泾店）", "address": "长宁区新渔路144号" },
                { "value": "香宜度麻辣香锅", "address": "长宁区淞虹路148号" },
                { "value": "凡仔汉堡（老真北路店）", "address": "上海市普陀区老真北路160号" },
                { "value": "港式小铺", "address": "上海市长宁区金钟路968号15楼15-105室" },
                { "value": "蜀香源麻辣香锅（剑河路店）", "address": "剑河路443-1" },
                { "value": "北京饺子馆", "address": "长宁区北新泾街道天山西路490-1号" },
                { "value": "饭典*新简餐（凌空SOHO店）", "address": "上海市长宁区金钟路968号9号楼地下一层9-83室" },
                { "value": "焦耳·川式快餐（金钟路店）", "address": "上海市金钟路633号地下一层甲部" },
                { "value": "动力鸡车", "address": "长宁区仙霞西路299弄3号101B" },
                { "value": "浏阳蒸菜", "address": "天山西路430号" },
                { "value": "四海游龙（天山西路店）", "address": "上海市长宁区天山西路" },
                { "value": "樱花食堂（凌空店）", "address": "上海市长宁区金钟路968号15楼15-105室" },
                { "value": "壹分米客家传统调制米粉(天山店)", "address": "天山西路428号" },
                { "value": "福荣祥烧腊（平溪路店）", "address": "上海市长宁区协和路福泉路255弄57-73号" },
                { "value": "速记黄焖鸡米饭", "address": "上海市长宁区北新泾街道金钟路180号1层01号摊位" },
                { "value": "红辣椒麻辣烫", "address": "上海市长宁区天山西路492号" },
                { "value": "(小杨生煎)西郊百联餐厅", "address": "长宁区仙霞西路88号百联2楼" },
                { "value": "阳阳麻辣烫", "address": "天山西路389号" },
                { "value": "南拳妈妈龙虾盖浇饭", "address": "普陀区金沙江路1699号鑫乐惠美食广场A13" }
            ];
        },
        querySearch(queryString, cb) {
            var restaurants = this.restaurants;
            var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        createFilter(queryString) {
            return (restaurant) => {
                return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
            };
        },
        handleSelect(item) {
            console.log(item);
        },
        fileUploadSuccess(response, file, fileList){
            alert("上传成功");
            this.generalFun();
            console.log('res:', response);
            console.log('file:', file);
            console.log('fileList:', fileList);
        },
        fileUploadError(err, file, fileList){
            alert("上传失败");
            console.log('err:', err);
            console.log('file:', file);
            console.log("fileList:" , fileList);
        },
        beforeFileUpload(file){
            // alert("上传之前:" , file);
            console.log('file:', file);

        }
    }

}
</script>


<style>
.el-table .warning-row {
    background: whitesmoke;
    /* background: #ffffff; */
}

.el-table .success-row {
    background: #f0f9eb;
}

.pagination {
    background-color: lavender;
    margin-right: 0%;
    text-align: right;
}

.searchWord .add1 {
    display: inline;
}

#btn {
    /* padding: 5px 10px;
            background: #00b0f0;
            color: #FFF;
            border: none;
            border-radius: 5px; */
}
</style>